package cn.sc.summer.mybatis.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.math.BigDecimal;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;

/**
 * 枚举类型：mysql基础类型与java类型对照表
 *
 * @author a-xin
 * @date 2024/8/26 15:06
 */
@Getter
@AllArgsConstructor
public enum MysqlJavaTypeEnum {

    LONG("bigint", Long.class, 1, -1),

    INT("int", Integer.class, 1, -1),
    INTEGER("integer", Integer.class, 2, -1),
    TINY_INT("tinyint", Integer.class, 3, -1),
    SMALL_INT("smallint", Integer.class, 4, -1),
    MEDIUM_INT("mediumint", Integer.class, 5, -1),

    BIT("bit", Boolean.class, 1, -1),
    BOOL("bool", Boolean.class, 2, -1),
    BOOLEAN("boolean", Boolean.class, 3, -1),

    DOUBLE("double", Double.class, 1, 2),
    FLOAT("float", Float.class, 1, 2),
    DECIMAL("decimal", BigDecimal.class, 1, 2),

    VARCHAR("varchar", String.class, 1, 255),
    CHAR("char", String.class, 2, 255),
    TEXT("text", String.class, 3, 255),
    TINY_TEXT("tinytext", String.class, 4, 255),
    MEDIUM_TEXT("mediumtext", String.class, 5, 255),
    LONG_TEXT("longtext", String.class, 6, 255),
    ENUM("enum", String.class, 7, 255),
    SET("set", String.class, 8, 255),
    JSON("json", String.class, 9, 255),

    DATE("datetime", Date.class, 1, 6),
    YEAR("year", Date.class, 2, 6),
    TIME("time", Time.class, 1, 6),
    TIME_STAMP("timestamp", Timestamp.class, 1, 6),

    BLOB("blob", Byte.class, 1, -1),
    BINARY("binary", Byte.class, 2, -1),
    VAR_BINARY("varbinary", Byte.class, 3, -1),
    TINY_BLOB("tinyblob", Byte.class, 4, -1),
    MEDIUM_BLOB("mediumblob", Byte.class, 5, -1),
    LONG_BLOB("longblob", Byte.class, 6, -1),
    ;

    /**
     * mysql类型
     */
    private final String dataSourceType;

    /**
     * java对应类型
     */
    private final Class<?> javaType;

    /**
     * 优先级，同类型优先级高的优先选择
     */
    private final Integer priority;

    /**
     * 字段默认长度，若为-1则不用添加长度属性
     */
    private final Integer defaultLength;

}
